# include <bits/stdc++.h>
# define MAXN 5023
using namespace std;

int f[MAXN][MAXN], la, lb;
char a[MAXN], b[MAXN];

int main() { 
# ifndef LOCAL
    freopen("lcslength.in", "r", stdin);
    freopen("lcslength.out", "w", stdout);
# else 
    freopen("in", "r", stdin);
# endif
    scanf("%s%s", a + 1, b + 1);
    la = strlen(a + 1);
    lb = strlen(b + 1);
    for(int i = 1; i <= la; i++) { 
        for(int j = 1; j <= lb; j++) { 
            if(a[i] == b[j]) f[i][j] = f[i - 1][j - 1] + 1;
            else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
        }
    }
    printf("%d\n",f[la][lb] - 1);
}
